package xyz.ssf.cloud.project.system.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import xyz.ssf.cloud.common.core.domain.PageResult;
import xyz.ssf.cloud.common.core.domain.R;
import xyz.ssf.cloud.project.system.domain.LoginLogQuery;
import xyz.ssf.cloud.project.system.domain.SysLoginLog;
import xyz.ssf.cloud.project.system.service.ISysLoginLogService;

/**
 * 系统访问日志情况信息
 * 
 * @author ssf
 */
@RestController
@RequestMapping("/system/loginlog")
public class SysLoginLogController {
    
    @Autowired
    private ISysLoginLogService loginLogService;

    /**
     * 查询登录日志列表
     */
    @GetMapping("/list")
    @PreAuthorize("hasAuthority('system:loginlog:list')")
    public R<PageResult<SysLoginLog>> list(LoginLogQuery query) {
        PageResult<SysLoginLog> pageResult = loginLogService.selectLoginLogPage(query);
        return R.success(pageResult);
    }

    /**
     * 删除登录日志
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('system:loginlog:remove')")
    public R<Void> remove(@PathVariable Long id) {
        loginLogService.deleteLoginLogById(id);
        return R.success();
    }

    /**
     * 批量删除登录日志
     */
    @DeleteMapping("/batch")
    @PreAuthorize("hasAuthority('system:loginlog:remove')")
    public R<Void> batchRemove(@RequestBody Long[] ids) {
        loginLogService.deleteLoginLogByIds(ids);
        return R.success();
    }

    /**
     * 清空登录日志
     */
    @DeleteMapping("/clean")
    @PreAuthorize("hasAuthority('system:loginlog:remove')")
    public R<Void> clean() {
        loginLogService.cleanLoginLog();
        return R.success();
    }
} 